import java.util.Arrays;

public class Solution1833 {
    public int maxIceCream(int[] costs, int coins) {
        Arrays.sort(costs);
        int i=0;
        while (i<costs.length && coins>=costs[i]){
            coins-=costs[i];
            i++;
        }
        return i;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1833().maxIceCream(new int[]{1,3,2,4,1},7));
    }
}
